<?php

declare (strict_types=1);

namespace app\html5\controller;

use app\Db2;
use app\H5AuthController;

class Article extends H5AuthController{
    //文章列表
    public function get_article_list(){

        $title = input('title');
        $listnum = input('listnum');
        $curpage = input('curpage');

        $where = [];
        if ($title) {
            $where['title'] = $title;
        }

        $list = Db2::get_datalist_page("article",[$where],$curpage,$listnum,null,'id desc');

        return rejson(200,'查询成功', $list);
    }

    //根绝id查询文章
    public function get_article(){
        $id = input('id');

        if(!$id || $id == 'undefined') return rejson(302,'id不能为空');

        $list = Db2::get_data("article",['id='.$id]);

        return rejson(200, '操作成功', $list);
    }

    //保存文章
    public function save_article(){
        $title = input('title');
        $url = input('url');
        $id = input('id');

        $data = [
            'title'=>$title,
            'url'=>$url
        ];

        if($id){
            $res = Db2::update_data('article',$data,['id'=>$id]);
        }else{
            $res = Db2::insert_data('article',$data);
        }


//        $list = Db2::get_datalist('article');

        return rejson(200, '操作成功');
    }
//    //修改文章
//    public function edit_article(){
//        $title = input('title');
//        $url = input('url');
//
//
//        $list = Db2::get_datalist('article');
//
//        return rejson(200, '操作成功', $list);
//    }

    //删除文章
    public function del_article_url(){
        $title = input('title');
        $url = input('url');


        $list = Db2::get_datalist('article');

        return rejson(200, '操作成功', $list);
    }
}